/*
 * common.h
 *
 *  Created on: 30 Sep, 2009
 *      Author: pankaj
 */

#ifndef COMMON_H_
#define COMMON_H_

//#define BUFFER_MGR_ON
//#define INDEX_ON
//#define DISK_SPACE_ON
//#define HEAP_ON

#define DEBUG 0
/*DEBUG == 1 for console debugging,DEBUG==2 for log debugging*/
//FILE *__logfp = fopen("logfile.txt","w+");
#define DEBUG_MSG(arg1,arg2) if (DEBUG)printf(arg1,arg2);
#define DEBUG_MSG_HEAP(arg1,arg2,debug) if(debug==1) printf(arg1,arg2);
//#define DEBUG_MSG_BUFFER(arg1,arg2,debug) if(debug==1) printf(arg1,arg2);
//#define DEBUG_MSG_INDEX(arg1,arg2,debug) if(debug==1) printf(arg1,arg2);
//#define DEBUG_MSG_DISKSPACE(arg1,arg2,debug) if(debug==1) printf(arg1,arg2);

/*
 * Key Formats or datatype identifier
 * Size support of each
 */

#define INTEGER 0
#define LONG 1
#define FLOAT 2
#define STRING 3
#define DATE 4
#define VARCHAR 5
#define TIME 6

#define MAX_VARCHAR 255
#define MAX_STRING 255
#define INTEGER_SIZE 4
#define LONG_SIZE 8
#define FLOAT_SIZE 16
#define STRING_SIZE 1
#define VARCHAR_SIZE 1
#define DATE_SIZE 8 /*yyyymmdd*/
#define TIME_SIZE 7 /*HHMMSS MILS*/

#define PAGE_SIZE 4096

#define INIT_PAGE_NOS 1000

#define SYSTABLE_DP 3
#define SYSCOL_DP 4
#define SYSIN_DP 5

// Maximum Length of the name of a "file" within a database
#define MAX_FILE_NAME 29
enum Status {ok,error};

/*
 * access types for buffer manager
 *
 */

#define WRITE 'w'
#define READ 'r'

namespace yadbms_common
{


typedef struct rid_struct{
	long pageno;
	int slotno;
}rid;

typedef struct systable_struct{
	int tableid;
	char tablename[20];
	long tableDP;

}systable;

typedef struct syscols_struct{
	int colnid;
	char colnname[20];
	int type;
	int char_size;//-1 if not char or varchar type;
	bool isNULL;
	bool isindex;
	bool isdefault;
	unsigned char colndefault[MAX_VARCHAR];
	long tableDP;
	int pposition;
}syscols;

typedef struct sysindex_struct{
	int idxid;
	long tableDP;
	int colms[50];
	unsigned char keyformat[50];
	int noskeyattr;
	long roothead;
}sysindex;

}


#endif /* COMMON_H_ */
